package com.example.todolist.utils;
import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;

import java.util.Date;

public class TokenUtils {
    /*
        生成token
    */
    private static final long EXPIRE_TIME= 2*60*60*1000;   //2小时
    public static final String secret="kunkuntiaowu";
    public static String genToken(String userId)
    {
        Date expiresAt = new Date(System.currentTimeMillis() + EXPIRE_TIME);
        return JWT.create().withAudience(userId)
                .withExpiresAt(expiresAt)  //两小时过期
                .sign(Algorithm.HMAC256(secret));  //以secret作为token的秘钥
    }
}
